<template>
	<u-modal v-model="showMsg" :title="msgTitle" :showTip="showTip" :titleStyle="titleStyle"
		:confirmColor="confirmColor" :content="noticeContent" :tipContent="tipContent" :borderTopStyle="borderTopStyle"
		@confirm="confirm"></u-modal>
</template>

<script>
	import utils from "../../utils/utils.js"
	export default {
		data() {
			return {
				promise: null,
				noticeInfo: {},
				showTip: false,
				msgTitle: '提示',
				tipContent: '发现火情',
				titleStyle: {},
				confirmColor: '#2979ff',
				borderTopStyle: {},
				borderTopStyleValue: {
					backgroundImage: `linear-gradient(269deg, #E74A50 0%, #FA805A 100%)`,
					borderRadius: '22.5px',
					margin: '0 20px 20px',
					fontFamily: 'PingFangSC-Medium',
					fontSize: '16px',
					letterSpacing: '0.32px'
				},
				fxhqTitleStyle: {
					backgroundImage: `url(https://ifire-oss.oss-cn-shanghai.aliyuncs.com/image/banner3.png)`,
					backgroundSize: 'cover',
					width: '100%',
					height: '170px'
				},
				sbyjTitleStyle: {
					backgroundImage: `url(https://ifire-oss.oss-cn-shanghai.aliyuncs.com/image/banner1.png)`,
					backgroundSize: 'cover',
					width: '100%',
					height: '170px'
				},
				sbgzTitleStyle: {
					backgroundImage: `url(https://ifire-oss.oss-cn-shanghai.aliyuncs.com/image/banner2.png)`,
					backgroundSize: 'cover',
					width: '100%',
					height: '170px'
				},
				showMsg: false,
				noticeContent: 'XX你好，今日XX时间XX建筑XX层XX区域XX位置发生火灾，请立即前往与XX协作，使用XX设备协助灭火。',
			}
		},
		props: {
			messageInfo: {
				type: Object,
				default: function() {
					return {
						name: "火情"
					}
				}
			}
		},
		methods: {
			show() {
				this.showMsg = true;
				this.noticeInfo = this.messageInfo
				if (this.noticeInfo.audio == 'true') {
					window.native.openAudio(9)
				} else {
					window.native.closeAudio(9)
				}
				if (this.noticeInfo.audioOpen == 'false') {
					window.native.closeAudio(this.noticeInfo.audioId)
				}

				// 默认状态
				this.msgTitle = '提示'
				this.showTip = false
				this.titleStyle = {}
				this.borderTopStyle = {}
				this.confirmColor = '#2979ff'
				if (this.noticeInfo.infoType == 2) {
					// 一键报警
					this.msgTitle = ''
					this.showTip = true
					this.tipContent = '发现火情'
					this.titleStyle = this.fxhqTitleStyle
					this.borderTopStyle = this.borderTopStyleValue
					this.confirmColor = '#FFFFFF'
				}
				if (this.noticeInfo.infoType == 1) {
					// 设备预警
					this.msgTitle = ''
					this.showTip = true
					this.tipContent = '设备预警'
					this.titleStyle = this.sbyjTitleStyle
					this.borderTopStyle = this.borderTopStyleValue
					this.confirmColor = '#FFFFFF'
				}
				if (this.noticeInfo.infoType == 3) {
					// 设备故障
					this.msgTitle = ''
					this.showTip = true
					this.tipContent = '设备预警'
					this.titleStyle = this.sbgzTitleStyle
					this.borderTopStyle = this.borderTopStyleValue
					this.confirmColor = '#FFFFFF'
				}
				this.noticeContent = this.noticeInfo.message
				this.promise = new Promise((resolve, reject) => {
					this.resolve = resolve;
					this.reject = reject;
				});
				// 返回promise对象
				return this.promise;
			},
			confirm() {
				if (this.noticeInfo.audio == 'true') {
					window.native.closeAudio(9)
				}
				if (this.noticeInfo.audioOpen == 'true') {
					window.native.closeAudio(9)
					window.native.openAudio(this.noticeInfo.audioId)
					uni.navigateTo({
						url: '/pages/index/abnormal/returnedSuccessfully?noticeId=' + this.noticeInfo
							.noticeInfoId + "&fireInfoId=" + this.noticeInfo.taskId
					});
				} else {
					this.utils.request("/api/app/user/getUserInfo", {}, "get", "app", true).then(res => {
						if (res.data.roleCode == "XZ-ADMIN" || res.data.roleCode == "XZ-YH") {
							//消灾企业用户
							uni.redirectTo({
								url: "/pages/index/index_xz"
							})
						} else if (res.data.roleCode == "WB-ADMIN" || res.data.roleCode == "WB-YH") {
							//维保企业用户
							uni.redirectTo({
								url: "/pages/index/index_wb"
							})
						}else if(res.data.roleCode == "JC-ADMIN" || res.data.roleCode == "JC-YH"){
							//维保企业用户
							uni.redirectTo({
								url:"/pages/index/index_jc"
							})
						} else {
							//其他企业用户
							uni.redirectTo({
								url: "/pages/index/index_qt"
							})
						}
					}).catch(error => {
						console.log(error)
					})
				}
				// if(this.noticeInfo.audioOpen=='false'){
				// 	window.native.closeAudio(this.noticeInfo.audioId)
				// }
				this.utils.request("/api/app/notice/updateReadStatus", {
					ucId: this.noticeInfo.noticeInfoId
				}, "post", "app", true).then(res => {
					console.log(res)
				}).catch(error => {
					console.log(error)
				})
				if (this.noticeInfo.equRounds == 'true') {
					window.native.getLocation(res => {
						this.utils.request("/api/admin/user/reportUserLocation", {
							location: res.data.addr,
							longitude: res.data.longitude,
							latitude: res.data.latitude
						}, "post", "app", true).then(res => {
							console.log(res)
						}).catch(error => {
							console.log(error)
						})
					})
					window.native.equRounds({
						title: this.noticeInfo.equipmentId,
						drill: this.noticeInfo.drill,
						ucId: this.noticeInfo.alarmInfoId,
						taskId: this.noticeInfo.taskId,
						token: utils.getStorageSync("authorization")
					})
				}
			}
		}
	}
</script>

<style>
</style>
